-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
43 lines (31 loc) · 1.09 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
double preco, contPreco = 0D, mediaPreco, mediaKiloDia;
int n = sc.nextInt();
String[] frutas = new String[n];
int[] contKilos = new int[n];
int cont = 0;
for (int i = 0; i < n; i++) {
preco = sc.nextDouble();
sc.next();
frutas[i] = sc.nextLine();
contPreco += preco;
contKilos[i] = 1;
for (int j = 0; j < frutas[i].length(); j++) {
if (frutas[i].charAt(j) == ' ') {
contKilos[i]++;
}
}
cont += contKilos[i];
System.out.println("day " + (i + 1) + ": " + contKilos[i] + " kg");
}
mediaPreco = contPreco / n;
mediaKiloDia = (double) cont / n;
System.out.printf("%.2f kg by day\n", mediaKiloDia);
System.out.printf("R$ %.2f by day\n", mediaPreco);
sc.close();
}
}